import { isVue3 } from "vue-demi";
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
    {
        path: '/:pathMatch(.*)',
        //访问主页的时候 重定向到index页面
        redirect: '/404',
    },
    {
        path: '/',
        component: () => import('@/views/administrator/administratorLogin.vue'),
    },
    {
        path: '/administratorLogin',
        name: 'AdministratorLogin', // 首页默认跳转路径
        component: () => import('@/views/administrator/administratorLogin.vue'),
    },
    {
        path: "/menuManagement",
        name: "MenuManagement",
        component: () => import('@/views/administrator/menuManagement/index.vue'),
    },
    // {
    //     path: "/user/:uid",  // 动态参数
    //     name: "user",
    //     component: User,  // 内部有router-view渲染要嵌套的路由
    //     children: [
    //         // 匹配形如 /user/lczmx 的url
    //         { path: "", component: UserHome },

    //         // 匹配形如 /user/lczmx/settings 的url
    //         { path: "settings", component: UserSettings, name: "user-settings" },

    //         // 匹配形如 /user/lczmx/profile 的url
    //         { path: "profile", component: UserProfile, name: "user-profile" }
    //     ]
    // },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    // //  从其他地方访问是否有这个地址
    // if (to.matched.length == 0) {
    //     from.path ? next({ name: from.name }) : next('*')
    // }
    next();
    const token = window.sessionStorage.getItem('token')
    // if (to.path !== '/administratorLogin' && !token) {
    //     next('/administratorLogin');
    // } else {
    //     if (to.name === 'AdministratorLogin' && token) {
    //         router.push('/')
    //     } else {
    //         next();
    //     }
    // }
});
export default router;